package code.D1223;

import java.util.ArrayDeque;
import java.util.Deque;

/**
 * author： yeswater
 * create： 2023/12/22
 *
 * 每日温度
 *
 */
public class T739 {
    public int[] dailyTemperatures(int[] ts) {
        int n = ts.length;
        int[] ans = new int[n];
        Deque<Integer> d = new ArrayDeque<>();
        for (int i = 0; i < n; i++) {
            while (!d.isEmpty() && ts[d.peekLast()] < ts[i]) {
                int idx = d.pollLast();
                ans[idx] = i - idx;
            }
            d.addLast(i);
        }
        return ans;
    }
    
    //作者：宫水三叶
    //链接：https://leetcode.cn/problems/daily-temperatures/solutions/1855543/by-ac_oier-aj5k/
}
